package seismosurfer.gui.charts;

import java.util.List;

import seismosurfer.util.TimeUtil;

/**
 * An abstract axis representation. Also, provides
 * some Legend implementations for various
 * time periods.
 *
 */
public abstract class Axis {
    protected List chartList;

    protected String label;

    public Axis(java.util.List chartList) {
        this.chartList = chartList;
    }

    public Axis() {
    }

    public String getLegend() {
        return label;
    }

    public void setLegend(String label) {
        this.label = label;
    }

    public List getChartList() {
        return chartList;
    }

    public void setCenturies() {
        setTime(new CenturiesLegend());
    }

    public void setYears() {
        setTime(new YearsLegend());
    }

    public void setMonths() {
        setTime(new MonthsLegend());
    }

    public void setDays() {
        setTime(new DaysLegend());
    }

    public void setHours() {
        setTime(new HoursLegend());
    }
    
    /**
     * Manipulates the TracePoint2D objects
     *  in their container to set the 
     *  proper time precision (day, yera, e.t.c.).
     * 
     * @param legend the Legend that handles time
     */
    protected abstract void setTime(Legend legend);

    static class CenturiesLegend extends Legend {

        public CenturiesLegend() {
            label = "Centuries";
        }

        public long getTime(long time) {
            return TimeUtil.getYear(time) / 100;
        }

    }

    static class YearsLegend extends Legend {

        public YearsLegend() {
            label = "Years";
        }

        public long getTime(long time) {
            return TimeUtil.getYear(time);
        }

    }

    static class MonthsLegend extends Legend {

        public MonthsLegend() {
            label = "Months";
        }

        public long getTime(long time) {
            return TimeUtil.getMonth(time);
        }

    }

    static class DaysLegend extends Legend {

        public DaysLegend() {
            label = "Days";
        }

        public long getTime(long time) {
            return TimeUtil.getDayOfYear(time);
        }

    }

    static class HoursLegend extends Legend {

        public HoursLegend() {
            label = "Hours";
        }

        public long getTime(long time) {
            return TimeUtil.getHourOfDay(time);
        }
    }

}
